package com.ljc.controller;


import com.ljc.entity.BaseResponse;
import com.ljc.entity.FollowingGroup;
import com.ljc.entity.UserFollowing;
import com.ljc.service.UserFollowingService;
import com.ljc.support.UserSupport;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class UserFollowingController {

    @Resource
    private UserFollowingService userFollowingService;

    @Resource
    private UserSupport userSupport;

    /**
     * 添加用户关注
     */
    @PostMapping("/user-followings")
    public BaseResponse<String> addUserFollowings(@RequestBody UserFollowing userFollowing) {
        Long userId = userSupport.getCurrentUserId();
        userFollowing.setUserId(userId);
        userFollowingService.addUserFollowings(userFollowing);
        return BaseResponse.success();
    }

    /**
     * 根据id 获取用户的关注列表（其中包括不同的关注类型，都要分别返回）
     */
    @GetMapping("/user-followings")
    public BaseResponse<List<FollowingGroup>> getUserFollowings() {
        Long userId = userSupport.getCurrentUserId();
        List<FollowingGroup> result = userFollowingService.getUserFollowings(userId);
        return new BaseResponse<>(result);
    }

    /**
     * 获取用户粉丝列表
     */
    @GetMapping("/user-fans")
    public BaseResponse<List<UserFollowing>> getUserFans() {
        Long userId = userSupport.getCurrentUserId();
        List<UserFollowing> result = userFollowingService.getUserFans(userId);
        return new BaseResponse<>(result);
    }

    /**
     * 新建用户关注分组
     */
    @PostMapping("/user-following-groups")
    public BaseResponse<Long> addUserFollowingGroups(@RequestBody FollowingGroup followingGroup) {
        Long userId = userSupport.getCurrentUserId();
        followingGroup.setUserId(userId);
        Long groupId = userFollowingService.addUserFollowingGroups(followingGroup);
        return new BaseResponse<>(groupId);
    }

    /**
     * 获取用户关注分组
     */
    @GetMapping("/user-following-groups")
    public BaseResponse<List<FollowingGroup>> getUserFollowingGroups() {
        Long userId = userSupport.getCurrentUserId();
        List<FollowingGroup> list = userFollowingService.getUserFollowingGroups(userId);
        return new BaseResponse<>(list);
    }

}
